from selenium.webdriver.common.by import By

from common.Utils import FormDriver


class FormLogonTest:
    url = "http://127.0.0.1:9580/sign-up.html"
    driver = ""
    def __init__(self):
        self.driver = FormDriver.driver
        self.driver.get(self.url)
    def FormLogonWebTest(self):
        # 查询log是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page.page-center > div > div.text-center.mb-4 > img")
        # 查询标题是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > h2")
        #用户名标题
        self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(2) > label")
        #用户名输入框
        self.driver.find_element(By.CSS_SELECTOR,"#username")
        #昵称标题
        self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(3) > label")
        #昵称输入框
        self.driver.find_element(By.CSS_SELECTOR,"#nickname")
        #密码标题
        self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(4) > label")
        #密码输入框
        self.driver.find_element(By.CSS_SELECTOR,"#password")
        #确认密码标题
        self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(5) > label")
        #确认密码输入框
        self.driver.find_element(By.CSS_SELECTOR,"#passwordRepeat")
        #同意条款按钮
        self.driver.find_element(By.CSS_SELECTOR,"#policy")
        #注册按钮
        self.driver.find_element(By.CSS_SELECTOR,"#submit")
        FormDriver.DribverScreeShot()


    def SendKeysName(self):
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("test")

    def SendKeysUnaame(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("255788")
    def SendKeysPassWord(self):
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
    def SendKeyRepeat(self):
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123456")


    def FormLogonSuc(self):
        #输入用户名
        self.SendKeysUnaame()
        #输入昵称
        self.SendKeysName()
        #输入密码
        self.SendKeysPassWord()
        #确认密码
        self.SendKeyRepeat()
        #同意条款
        self.driver.find_element(By.CSS_SELECTOR,"#policy").click()
        #点击注册
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        FormDriver.DribverScreeShot()

    def FormLogonDefe1(self):
        self.SendKeysUnaame()
        FormDriver.DribverScreeShot()


    def FormLogonDefe2(self):
        self.SendKeysName()
        self.SendKeyRepeat()
        FormDriver.DribverScreeShot()

    def FormLogonDefe3(self):
        self.SendKeysPassWord()
        self.driver.find_element(By.CSS_SELECTOR,"#policy").click()
        FormDriver.DribverScreeShot()

    def FormLogonDefe4(self):
        self.SendKeysName()
        self.SendKeysPassWord()
        FormDriver.DribverScreeShot()

    def FormLogonDefe5(self):
        self.SendKeyRepeat()
        self.driver.find_element(By.CSS_SELECTOR,"#policy").click()
        FormDriver.DribverScreeShot()



